package com.tencent.mm.opensdk.diffdev.a;

import com.huawei.hms.framework.network.restclient.hwhttp.HttpContants;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.utils.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public final class e {
    public static byte[] a(String str) {
        InputStream inputStream;
        HttpURLConnection httpURLConnection;
        MalformedURLException malformedURLException;
        ByteArrayOutputStream byteArrayOutputStream;
        Throwable th;
        HttpURLConnection httpURLConnection2;
        InputStream inputStream2;
        IOException iOException;
        IOException iOException2;
        Exception exception;
        Exception exception2;
        Throwable th2;
        if (str == null || str.length() == 0) {
            Log.e("MicroMsg.SDK.NetUtil", "httpGet, url is null");
            return null;
        }
        ByteArrayOutputStream byteArrayOutputStream2;
        try {
            HttpURLConnection httpURLConnection3 = (HttpURLConnection) new URL(str).openConnection();
            if (httpURLConnection3 == null) {
                try {
                    Log.e("MicroMsg.SDK.NetUtil", "open connection failed.");
                    if (httpURLConnection3 != null) {
                        try {
                            httpURLConnection3.disconnect();
                        } catch (Throwable th3) {
                        }
                    }
                    return null;
                } catch (MalformedURLException e) {
                    inputStream = null;
                    httpURLConnection = httpURLConnection3;
                    malformedURLException = e;
                    byteArrayOutputStream = null;
                    try {
                        Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + malformedURLException.getMessage());
                        if (httpURLConnection != null) {
                            try {
                                httpURLConnection.disconnect();
                            } catch (Throwable th4) {
                            }
                        }
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (Throwable th5) {
                            }
                        }
                        if (byteArrayOutputStream != null) {
                            try {
                                byteArrayOutputStream.close();
                            } catch (Throwable th6) {
                            }
                        }
                        return null;
                    } catch (Throwable th7) {
                        th = th7;
                        ByteArrayOutputStream byteArrayOutputStream3 = byteArrayOutputStream;
                        httpURLConnection2 = httpURLConnection;
                        inputStream2 = inputStream;
                        byteArrayOutputStream2 = byteArrayOutputStream3;
                        if (httpURLConnection2 != null) {
                            try {
                                httpURLConnection2.disconnect();
                            } catch (Throwable th8) {
                            }
                        }
                        if (inputStream2 != null) {
                            try {
                                inputStream2.close();
                            } catch (Throwable th9) {
                            }
                        }
                        if (byteArrayOutputStream2 != null) {
                            try {
                                byteArrayOutputStream2.close();
                            } catch (Throwable th10) {
                            }
                        }
                        throw th;
                    }
                } catch (IOException e2) {
                    byteArrayOutputStream2 = null;
                    inputStream2 = null;
                    iOException = e2;
                    httpURLConnection2 = httpURLConnection3;
                    iOException2 = iOException;
                    try {
                        Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + iOException2.getMessage());
                        if (httpURLConnection2 != null) {
                            try {
                                httpURLConnection2.disconnect();
                            } catch (Throwable th11) {
                            }
                        }
                        if (inputStream2 != null) {
                            try {
                                inputStream2.close();
                            } catch (Throwable th12) {
                            }
                        }
                        if (byteArrayOutputStream2 != null) {
                            try {
                                byteArrayOutputStream2.close();
                            } catch (Throwable th13) {
                            }
                        }
                        return null;
                    } catch (Throwable th14) {
                        th = th14;
                        if (httpURLConnection2 != null) {
                            httpURLConnection2.disconnect();
                        }
                        if (inputStream2 != null) {
                            inputStream2.close();
                        }
                        if (byteArrayOutputStream2 != null) {
                            byteArrayOutputStream2.close();
                        }
                        throw th;
                    }
                } catch (Exception e3) {
                    byteArrayOutputStream2 = null;
                    inputStream2 = null;
                    exception = e3;
                    httpURLConnection2 = httpURLConnection3;
                    exception2 = exception;
                    Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + exception2.getMessage());
                    if (httpURLConnection2 != null) {
                        try {
                            httpURLConnection2.disconnect();
                        } catch (Throwable th15) {
                        }
                    }
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (Throwable th16) {
                        }
                    }
                    if (byteArrayOutputStream2 != null) {
                        try {
                            byteArrayOutputStream2.close();
                        } catch (Throwable th17) {
                        }
                    }
                    return null;
                } catch (Throwable th18) {
                    byteArrayOutputStream2 = null;
                    inputStream2 = null;
                    th2 = th18;
                    httpURLConnection2 = httpURLConnection3;
                    th = th2;
                    if (httpURLConnection2 != null) {
                        httpURLConnection2.disconnect();
                    }
                    if (inputStream2 != null) {
                        inputStream2.close();
                    }
                    if (byteArrayOutputStream2 != null) {
                        byteArrayOutputStream2.close();
                    }
                    throw th;
                }
            }
            httpURLConnection3.setRequestMethod(HttpContants.HTTP_METHOD_GET);
            httpURLConnection3.setConnectTimeout(60000);
            httpURLConnection3.setReadTimeout(60000);
            if (httpURLConnection3.getResponseCode() >= 300) {
                Log.e("MicroMsg.SDK.NetUtil", "httpURLConnectionGet 300");
                if (httpURLConnection3 != null) {
                    try {
                        httpURLConnection3.disconnect();
                    } catch (Throwable th19) {
                    }
                }
                return null;
            }
            inputStream2 = httpURLConnection3.getInputStream();
            try {
                byteArrayOutputStream2 = new ByteArrayOutputStream();
                try {
                    byte[] bArr = new byte[WXMediaMessage.DESCRIPTION_LENGTH_LIMIT];
                    while (true) {
                        int read = inputStream2.read(bArr);
                        if (read == -1) {
                            break;
                        }
                        byteArrayOutputStream2.write(bArr, 0, read);
                    }
                    bArr = byteArrayOutputStream2.toByteArray();
                    Log.d("MicroMsg.SDK.NetUtil", "httpGet end");
                    if (httpURLConnection3 != null) {
                        try {
                            httpURLConnection3.disconnect();
                        } catch (Throwable th20) {
                        }
                    }
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (Throwable th21) {
                        }
                    }
                    try {
                        byteArrayOutputStream2.close();
                    } catch (Throwable th22) {
                    }
                    return bArr;
                } catch (MalformedURLException e4) {
                    MalformedURLException malformedURLException2 = e4;
                    byteArrayOutputStream = byteArrayOutputStream2;
                    inputStream = inputStream2;
                    httpURLConnection = httpURLConnection3;
                    malformedURLException = malformedURLException2;
                    Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + malformedURLException.getMessage());
                    if (httpURLConnection != null) {
                        httpURLConnection.disconnect();
                    }
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    if (byteArrayOutputStream != null) {
                        byteArrayOutputStream.close();
                    }
                    return null;
                } catch (IOException e22) {
                    iOException = e22;
                    httpURLConnection2 = httpURLConnection3;
                    iOException2 = iOException;
                    Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + iOException2.getMessage());
                    if (httpURLConnection2 != null) {
                        httpURLConnection2.disconnect();
                    }
                    if (inputStream2 != null) {
                        inputStream2.close();
                    }
                    if (byteArrayOutputStream2 != null) {
                        byteArrayOutputStream2.close();
                    }
                    return null;
                } catch (Exception e32) {
                    exception = e32;
                    httpURLConnection2 = httpURLConnection3;
                    exception2 = exception;
                    Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + exception2.getMessage());
                    if (httpURLConnection2 != null) {
                        httpURLConnection2.disconnect();
                    }
                    if (inputStream2 != null) {
                        inputStream2.close();
                    }
                    if (byteArrayOutputStream2 != null) {
                        byteArrayOutputStream2.close();
                    }
                    return null;
                } catch (Throwable th23) {
                    httpURLConnection2 = httpURLConnection3;
                    th = th23;
                    if (httpURLConnection2 != null) {
                        httpURLConnection2.disconnect();
                    }
                    if (inputStream2 != null) {
                        inputStream2.close();
                    }
                    if (byteArrayOutputStream2 != null) {
                        byteArrayOutputStream2.close();
                    }
                    throw th;
                }
            } catch (MalformedURLException e42) {
                inputStream = inputStream2;
                httpURLConnection = httpURLConnection3;
                malformedURLException = e42;
                byteArrayOutputStream = null;
                Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + malformedURLException.getMessage());
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                if (inputStream != null) {
                    inputStream.close();
                }
                if (byteArrayOutputStream != null) {
                    byteArrayOutputStream.close();
                }
                return null;
            } catch (IOException e222) {
                byteArrayOutputStream2 = null;
                iOException = e222;
                httpURLConnection2 = httpURLConnection3;
                iOException2 = iOException;
                Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + iOException2.getMessage());
                if (httpURLConnection2 != null) {
                    httpURLConnection2.disconnect();
                }
                if (inputStream2 != null) {
                    inputStream2.close();
                }
                if (byteArrayOutputStream2 != null) {
                    byteArrayOutputStream2.close();
                }
                return null;
            } catch (Exception e322) {
                byteArrayOutputStream2 = null;
                exception = e322;
                httpURLConnection2 = httpURLConnection3;
                exception2 = exception;
                Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + exception2.getMessage());
                if (httpURLConnection2 != null) {
                    httpURLConnection2.disconnect();
                }
                if (inputStream2 != null) {
                    inputStream2.close();
                }
                if (byteArrayOutputStream2 != null) {
                    byteArrayOutputStream2.close();
                }
                return null;
            } catch (Throwable th182) {
                byteArrayOutputStream2 = null;
                th2 = th182;
                httpURLConnection2 = httpURLConnection3;
                th = th2;
                if (httpURLConnection2 != null) {
                    httpURLConnection2.disconnect();
                }
                if (inputStream2 != null) {
                    inputStream2.close();
                }
                if (byteArrayOutputStream2 != null) {
                    byteArrayOutputStream2.close();
                }
                throw th;
            }
        } catch (MalformedURLException e5) {
            malformedURLException = e5;
            byteArrayOutputStream = null;
            inputStream = null;
            httpURLConnection = null;
            Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + malformedURLException.getMessage());
            if (httpURLConnection != null) {
                httpURLConnection.disconnect();
            }
            if (inputStream != null) {
                inputStream.close();
            }
            if (byteArrayOutputStream != null) {
                byteArrayOutputStream.close();
            }
            return null;
        } catch (IOException e6) {
            iOException2 = e6;
            byteArrayOutputStream2 = null;
            inputStream2 = null;
            httpURLConnection2 = null;
            Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + iOException2.getMessage());
            if (httpURLConnection2 != null) {
                httpURLConnection2.disconnect();
            }
            if (inputStream2 != null) {
                inputStream2.close();
            }
            if (byteArrayOutputStream2 != null) {
                byteArrayOutputStream2.close();
            }
            return null;
        } catch (Exception e7) {
            exception2 = e7;
            byteArrayOutputStream2 = null;
            inputStream2 = null;
            httpURLConnection2 = null;
            Log.e("MicroMsg.SDK.NetUtil", "httpGet ex:" + exception2.getMessage());
            if (httpURLConnection2 != null) {
                httpURLConnection2.disconnect();
            }
            if (inputStream2 != null) {
                inputStream2.close();
            }
            if (byteArrayOutputStream2 != null) {
                byteArrayOutputStream2.close();
            }
            return null;
        } catch (Throwable th24) {
            th = th24;
            byteArrayOutputStream2 = null;
            inputStream2 = null;
            httpURLConnection2 = null;
            if (httpURLConnection2 != null) {
                httpURLConnection2.disconnect();
            }
            if (inputStream2 != null) {
                inputStream2.close();
            }
            if (byteArrayOutputStream2 != null) {
                byteArrayOutputStream2.close();
            }
            throw th;
        }
    }
}
